<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/common/sale/include/common-base.jsp"%>
   <script src="/common/sale/MsgToos.js"></script>
  <title>发行申购</title>
</head>
<body class="hold-transition ${sysUserColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/sale/top-user.jsp" %>
  <!-- top end -->
<!-- left start -->
  <%@include file="/common/sale/left-user.jsp" %>
<!-- left end-->
 <!-- main start -->
  <div class="content-wrapper">
	  <div class="content">
	    <div class="row">
	       <div class="col-lg-12 rightmt">
	           <div class="right_box">
	               <!-- 我的挂牌搜索 开始-->
			       <form id="searchForm" class="form-horizontal">
			            <input type="hidden" name="pageName" value="bjtesale-pub-list.jsp"/>
						<input type="hidden" name="formName" value="searchForm1">
						<input type="hidden" name="trsSale.w_delStatus" value="F">
				    	<!-- <input type="hidden" name="orderBy"  value="trsSale.pro_no" /> -->
				    	<input type="hidden" name="trsSale.w_saleStatus" value="30"/><!-- 姚添加 -->
				    	<input type="hidden" name="orderBy"  value="trsSale.create_time desc" />
				    	
				    	
				         <!-- 我的挂牌搜索 start -->
						 <h4 class="user_title">
						   <p><i class="fa fa-search"></i><span>商品搜索</span></p>
						 </h4>
					    <!-- 我的挂牌搜索 end -->   
			            	<div class="form-group">
								<label  class="col-sm-3 control-label">
									商品代码：
								</label>
								<div class="col-sm-2">
									<input type="text" class="form-control"  name="trsSale.wl_proNo" id="proNo" value="" />
								</div>
								<label  class="col-sm-3 control-label">
									商品名称：
								</label>
								<div class="col-sm-2">
									<input type="text" class="form-control"  name="trsSale.wl_proName" id="proName" value="" />
								</div>
								
							</div>
			            <center>
				            <div class="box-footer clearfix">
				              <a href="javascript:void(0)" class="btn btn-danger " onclick="getTableData();">查询</a>
				              <a href="javascript:void(0)" class="btn btn-primary" onclick="FormUtil.cleanData('searchForm');">重置</a>
				            </div>
			            </center>
			         </form>
			        </div>
			       <!-- 我的挂牌搜索 结束-->
			       
			       <div class="right_box" style="margin-top:20px;">
				         <!-- 我的挂牌搜索 start -->
								 <h4 class="user_title">
								   <p><i class="fa fa-line-chart"></i><span>发行商品</span></p>
								 </h4>
					    <!-- 我的挂牌搜索 end -->   
			            <table id="dataList" class="table table-hover user_table" >
			                <thead>
			                <tr>
			                  <th>序号</th>
			                  <th>商品代码</th>
			                  <th class="text_c">商品名称</th>
			                  <th>发行价格</th>
			                  <th>发行总量</th>
			                  <th>申购截止</th>
			                  <th class="text_c">活动名称</th>
			                  <th>操作</th>
			                </tr>
			                </thead>
			                <tbody id="dataList-body">
			                </tbody>
			              </table>
		         	    <center>
		    	  			  <ul id="dataList-page"></ul>
		        		</center>
			        </div>
			     
			       <!-- 我的挂牌搜索 结束-->
	       
	        </div>
	       <!-- right end -->
	      </div>
	      </div>
	      </div>
	 <!-- mainrow end -->
</div>
 <!-- main end -->     
    
   <!-- foot start -->
<%@include file="/common/sale/foot-user.jsp" %>
 <!-- foot start -->    
<div class="modal fade" id="my_modal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">商品申购</font>
						</h4>
					</div>
					<div class="modal-body">
						<div class="nav-tabs-custom">
					            <form class="form-horizontal" role="form" id="addForm1" action="javascript:void(0)">
									    <input type="hidden" id="addForm1_formToken" name="formToken" />
										<input type="hidden" name="doCode" value="dymicSql"/>
										<input type="hidden" name="pageName" value="bjtesale-buy-list.jsp"/>
										<input type="hidden" name="formName" value="addForm1"/>
										
										<input type="hidden" name="cateNo" value="bjtesale"/>
										<input type="hidden" name="constantType" value="buy_status"/>
										<input type="hidden" name="constantStatus" value="10"/>
										<input type="hidden" name="saleId" data-name="trsSale.saleId" class="clean"/>
										
										<input type="hidden" name="trsBuy.saleId" data-name="trsSale.saleId" class="clean"/>
										<input type="hidden" name="trsBuy.buyStatus" value="10"/>
										<input type="hidden" name="trsBuy.rengouType" value="2"/>
										<input type="hidden" name="trsBuy.sysName" value="sale"/>
										<input type="hidden" name="trsBuy.userId" value="${loginUser.userId}"/>
										<input type="hidden" name="trsBuy.userOwner" value="${loginUser.userEname}"/>
										<input type="hidden" name="trsBuy.userName" value="${loginUser.userEname}"/>
										<input type="hidden" name="trsBuy.userRealName" value="${loginUser.userCname}"/>
										<input type="hidden" name="trsBuy.proId" data-name="trsSale.proId"  class="clean"/>
										<input type="hidden" name="userSettleNo" value="${loginUser.user.cardNum}"/>
										<input type="hidden" name="trsBuy.saleName" data-name="trsSale.saleName"  class="clean"/>

							                <!--trsSale start-->
											<div class="form-group col-sm-12">
							                	<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">商品代码：</label>
													<div class="col-sm-8">
														<input name="trsBuy.proNo" readonly="readonly" data-name="trsSale.proNo"  class="form-control clean"/>
													</div>
												</div>
												
							                	<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">商品名称：</label>
													<div class="col-sm-8">
											  			<input name="trsBuy.proName" readonly="readonly" data-name="trsSale.proName"  class="form-control clean"/>
													</div>
												</div>
												
							                	<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">发行价格：</label>
													<div class="col-sm-8">
														<input  readonly="readonly" data-name="trsSale.priceInit"  class="form-control clean"/>
													</div>
												</div>
												
												<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">发行总量：</label>
													<div class="col-sm-8">
														<input  readonly="readonly" data-name="trsSale.saleNum"  class="form-control clean"/>
													</div>
												</div>
											</div>
											
											<div class="form-group col-sm-12" id="rulespro-body" >
												
											</div>
						                	
						                	
						                	<div class="form-group col-sm-12">
						                		<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">申购价格：</label>
													<div class="col-sm-8">
														<input type="text" name="trsBuy.price" data-name="trsSale.priceInit" readonly="readonly" class="form-control clean"/>
													</div>
												</div>
												<div class="form-group col-sm-6">
													<label  class="col-sm-4 control-label">申购数量：</label>
													<div class="col-sm-8">
														<input type="text" id="trsBuy_num" name="trsBuy.num" class="form-control clean" maxLength="50" required placeholder="必填项" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
														<!-- <input type="text" id="trsBuy_num" name="trsBuy.num" class="form-control clean" maxLength="50" required placeholder="必填项" /> -->
													</div>
												</div>
											</div>
											
											
								        	<!--trsSale end-->
								        
					                    
					                    <div class="form-group">
								        	<div class="col-sm-12">
									         <div class="box-footer text-center">
									         	<button class="btn btn-danger" type="button" style="width: 200px;" onclick="submitForm1('addForm1');"> 提 交 </button>
					            			</div>
				            				</div>
				            			</div>
					                  </form>
					            <!-- tab content e -->
				          </div>	
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>   


<div id="productInfoDiv" style="display:none;">
<form id="formFundsOpen" name="myForm" class="regdivbox">
	<input type="hidden" name="userEname" value="${loginUser.userEname}"/>
	<input type="hidden" name="userCname" value="${loginUser.userCname}"/>
	<table class="tab_info">
		<tr>
  		<th colspan="4" style="text-align: center;" >
   			<label data-name="trpProduct.proName" style="color: black;font-size: 20px" ></label>
  		</th>
		</tr>
		<tr>
	  		<th>商品代码：</th>
	  		<td>
	  			<span data-name="trpProduct.proNo"></span>
	  		</td>
	  		<th>商品简称：</th>
	  		<td>
	  			<span data-name="trpProduct.shortName"></span>
	  		</td>
		</tr>
		<tr>
	  		<th>商品单位：</th>
	  		<td>
	  			<span data-name="trpProduct.proUnit" data-dict-url="doCode=dictItemList&cateEname=productUnit"></span>
	  		</td>
	  		<th>商品状态：</th>
	  		<td>
	  			<span data-name="trpProduct.proStatus" data-dict-url="doCode=dictItemList&cateEname=proStatus"></span>
	  		</td>
		</tr>
		<tr>
	  		<th>商品描述：</th>
	  		<td colspan="3">
				<span data-name="trpProduct.proRemark"></span>
	  		</td>
		</tr>
	 </table>
	</form>
 </div>
</body>
	<script type="text/template" id="dataList-template">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td class="text_c"><?=(pageObj.currentPage-1)*10+(i+1)?></td>
					<td class="text_c"><a href="javascript:getProductInfo('<?=rows[i].proId?>');" / ><?=rows[i].proNo?></td>
					<td class="text_l"><a href="javascript:getProductInfo('<?=rows[i].proId?>');" / ><?=strUtil.subStr(rows[i].proName,7)?></td>
					<td class="text_r">￥<?=fmoney(rows[i].priceInit)?></td>
					<td class="text_r"><?=strUtil.doNull(rows[i].saleNum,'-')?></td>
					<td class="text_c"><?=strUtil.doNull(rows[i].saleDateEnd,'-')?></td>
					<td class="text_c" title="<?=rows[i].saleName?>"><?=strUtil.subStr(rows[i].saleName,7)?></td>	
					<td class="text_c">
						<button type="button" class="btn btn-danger btn-xs" onclick="showBuy('<?=rows[i].saleId?>')"> 申 购 </button>&nbsp;
					</td>
				</tr>
     		<?}?>
	</script>
	<script type="text/template" id="rulespro-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<div class="form-group col-sm-6">
			<label  class="col-sm-4 control-label"><?=rows[i].paramName?>：</label>
			<div class="col-sm-8">
				<input class="form-control fx12" value="<?=strUtil.doNull(rows[i].paramNo,'')?>"  readonly="readonly"/>
			</div>
		</div>
   <?}?>  		
</script>

<script>
var clickMenu= "sale-list";
var id,myPage,dataListId,searchFormId,isShowLog,tableSort,tableId,token;
myPage = 10;
dataListId = "dataList";
searchFormId = "searchForm";
tableSort = "trsSale";
tableId = "saleId";
isShowLog = true;

var paramData = {};
$(function () {
	setToken();
	getTableData();
});
//获取发行规则表
function getSaleRulesList(saleId){
	var rulespro="rulespro";
	var paramData = {"doCode":"dymicSql","modelTypes":"s_trsRulesPro","trsRulesPro.w_saleId":saleId,"trsRulesPro.w_showFlag":"T","orderBy":"trsRulesPro.rules_no nulls last"};
	
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:paramData,
		   dataType:'json',
		   success: function(myData){
			   
		   console.log(myData);

			var data = baidu.template(rulespro+"-template",eval(myData));  
			$("#"+rulespro+"-body").html(data);
			
		   }
		});	
}

//清空数据
function cleanData(id){
	$('#'+id).find(".clean").val("");//按照样式清空；
}

function getTableData(){
	deleteAllRow('dataListId');
	//搜索框去除空格
	 $("#proNo").val($("#proNo").val().trim());
	 $("#proName").val($("#proName").val().trim());
	 
	 $.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
		   if(isShowLog)console.log(myData);
			var data = baidu.template(dataListId+"-template",eval(myData));  
			$("#"+dataListId+"-body").html(data);
			  var option= {
					   ele:$("#"+dataListId+"-page")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$("#"+searchFormId).serialize()
				   }
				generatePages(option);
		   }
		});	
  }

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (var i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function cannel(modalId){
	$('#'+modalId).modal('hide');
}

function refresh(){
    //window.location.reload();
	window.location.reload();
}



function submitForm1(formId){
	var trsBuyNum = $("#trsBuy_num");
	if(strUtil.isNull(trsBuyNum.val())){
		//layer.alert('申购数量不能为空！', {closeBtn: 0 });
		//return;
		$("#trsBuy_num").nextAll("span").remove();
		$("#trsBuy_num").after("<span style='color:red;'>申购数量不能为空，只能输入数字！</span>");
		return;
	}
	/*
	//1.校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过
	    return;  
	} */
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	        	layer.alert("操作成功！",{yes:function(){
		        	cannel("my_modal_add");
		        	refresh();
	        	}});
	        	if(myData.ids){
	        	}
	    	}else{
	    		layer.alert(MsgToos.getMsg(myData.msg));
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	
 }
	

 
//回车查询
document.onkeydown=function mykeyDown(e){  
      //compatible IE and firefox because there is not event in firefox  
       e = e||event;  
       if(e.keyCode == 13) {getTableData();}   
       return;  
};


function showBuy(saleId){
	cleanData("addForm1");//清除上次查看记录
	//cleanJiaoyan("addForm1");//清除上次校验记录
	$("#trsBuy_num").nextAll("span").remove();
	var paramLoadData = {"formName":"searchForm1","pageName":"bjtesale-pub-list.jsp","trsSale.w_saleId":saleId};
	$.ajax({
	    type:'get',
	   	url:common_info_url+"?doCode=dymicSql",
	    data: paramLoadData,
	    async:false,
	    dataType:"json",
	    success: function(myData){
	    	console.log(myData);
	    	
			FormUtil.loadView("trsSale", myData);
			
			getSaleRulesList(saleId);
			
			$("#my_modal_add").modal("show");
			//setValidate("addForm1");//2.校验规则-弹框窗口加载定义方法
	  	}
	});
}

//校验申购数量
/*
function checkNum(){
    //获得文本框的值
    var num = document.getElementById("trsBuy_num").value;
    var num = document.getElementById("trsBuy_num").value;
    var num = document.getElementById("trsBuy_num").value;
    
    //判断是否输入用户名
    if(num.trim() ==""){
    	 document.getElementById("trsBuy_num").innerHTML = "申购数量不能为空！";
         return;
    }
   
}
*/

function getProductInfo(proId){
	getProductData(proId);
	popDiv('productInfoDiv');

}


function getProductData(proId){
	var paramLoadData = {"formName":"searchForm1","pageName":"bjtesale-reg-list.jsp","trpProduct.w_proId":proId};
	$.ajax({
	    type:'get',
	   	url:common_info_url+"?doCode=dymicSql",
	    data: paramLoadData,
	    async:false,
	    dataType:"json",
	    success: function(myData){
			FormUtil.loadView("trpProduct", myData);
	  	}
	});
}

function popDiv(divId){
	layer.open({
	    type: 1,
	    title: '商品信息',
	    closeBtn: 1,offset: '200px',
	    area: ['650px','350px'],
	    //skin: 'layui-layer-nobg', //没有背景色
	    shadeClose: true,
	    content: $('#'+divId)
	});
}

//1.表单提交前：校验规则-定义
function setValidate(formId){
	$('#'+formId).bootstrapValidator({
	 //  excluded: [':disabled'],
	   feedbackIcons: {
	        valid: 'glyphicon glyphicon-ok',
	        invalid: 'glyphicon glyphicon-remove',
	        validating: 'glyphicon glyphicon-refresh'
	    },
	    fields: {
	      
	        "trsBuy.num": {
	            validators: {
	                notEmpty: {
	                    message: '申购数量不能为空！'	
	                },
	                numeric: {
		                message: '只能填写数字，且申购数量不能超过发行总量~'
		            },
		            greaterThan:{
                        value: 1,
	                    message: '申购数量不能小于1！'
	                }
	            }
	        }
	    }
	});
}

//清空校验规则
function cleanJiaoyan(formId){
	alert(111);
	var validate = $('#'+formId).data('bootstrapValidator').validate();
		validate.resetForm();
}

</script>
</html>
